package com.bw.aop;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

@Component
@Aspect
public class MyAroudAop {
    /**
     * 环绕通知
     * @param joinPoint
     * @return
     */
    @Around("execution(* com.bw.service.*.*(..))")
    public Object b(ProceedingJoinPoint joinPoint) throws Throwable {

        String name = joinPoint.getSignature().getName();// 获取方法名
        System.out.println("方法名是 " + name);

        Object[] args = joinPoint.getArgs();
        System.out.println("方法的入参是 " + JSON.toJSONString(args));

        long l = System.currentTimeMillis(); // 原方法执行之前
        Object proceed = joinPoint.proceed(); // 执行原方法
        long l2 = System.currentTimeMillis(); // 原方法执行之后
        System.out.println("方法耗时 "  +  (l2-l));
        System.out.println("方法的返参 " + JSON.toJSONString(proceed));
        return proceed;
    }

}
